package com.fengze.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.fengze.business.vo.PerformanceRecordVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fengze.common.annotation.Log;
import com.fengze.common.core.controller.BaseController;
import com.fengze.common.core.domain.AjaxResult;
import com.fengze.common.enums.BusinessType;
import com.fengze.business.domain.PerformanceRecord;
import com.fengze.business.service.IPerformanceRecordService;
import com.fengze.common.utils.poi.ExcelUtil;
import com.fengze.common.core.page.TableDataInfo;

/**
 * 履约记录Controller
 * 
 * @author lug
 * @date 2024-02-04
 */
@RestController
@RequestMapping("/performance/record")
public class PerformanceRecordController extends BaseController
{
    @Autowired
    private IPerformanceRecordService performanceRecordService;

    /**
     * 查询履约记录列表
     */
    @PreAuthorize("@ss.hasPermi('performance:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(PerformanceRecord performanceRecord)
    {
        startPage();
//        List<PerformanceRecord> list = performanceRecordService.selectPerformanceRecordList(performanceRecord);
        List<PerformanceRecordVO> list = performanceRecordService.selectPerformanceRecordVOList(performanceRecord);
        return getDataTable(list);
    }

    /**
     * 导出履约记录列表
     */
    @PreAuthorize("@ss.hasPermi('performance:record:export')")
    @Log(title = "履约记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PerformanceRecord performanceRecord)
    {
        List<PerformanceRecord> list = performanceRecordService.selectPerformanceRecordList(performanceRecord);
        ExcelUtil<PerformanceRecord> util = new ExcelUtil<PerformanceRecord>(PerformanceRecord.class);
        util.exportExcel(response, list, "履约记录数据");
    }

    /**
     * 获取履约记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('performance:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(performanceRecordService.selectVOById(id));
    }

    /**
     * 新增履约记录
     */
    @PreAuthorize("@ss.hasPermi('performance:record:add')")
    @Log(title = "履约记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PerformanceRecord performanceRecord)
    {
        return toAjax(performanceRecordService.insertPerformanceRecord(performanceRecord));
    }

    /**
     * 修改履约记录
     */
    @PreAuthorize("@ss.hasPermi('performance:record:edit')")
    @Log(title = "履约记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PerformanceRecord performanceRecord)
    {
        return toAjax(performanceRecordService.updatePerformanceRecord(performanceRecord));
    }

    /**
     * 删除履约记录
     */
    @PreAuthorize("@ss.hasPermi('performance:record:remove')")
    @Log(title = "履约记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(performanceRecordService.deletePerformanceRecordByIds(ids));
    }
}
